<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */

if (!defined("Login_lib_include")){
	define("Login_lib_include", 1);

/**
 * 取得上層序號字串
 * @param	intUserID 使用者序號
 * @return	回傳 String -> 成功，false -> 失敗，1,2,4,.....,n
 */
	function GetStringParentID($intUserID){
		global $_Conn, $$_Conn;

		$_strSQL = "select ParentID from `bet_Member` where ID = ".$intUserID;
		if(!$RS = PMA_mysql_query($_strSQL, $$_Conn)){
			$GLOBALS["errormessage"] = "Find Member Parent Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nSQL:".$_strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		if(PMA_mysql_num_rows($RS) > 0){
			$Rows = PMA_mysql_fetch_object($RS);
			if($Rows -> ParentID == 0){
				return ",";
			}else{
				$_strID = $Rows -> ParentID;
				if(!$tmp = GetStringParentID($Rows -> ParentID))return false;
				if($tmp != ",")$_strID .= ",".$tmp;
			}
		}else{
			return ",";
		}

		return $_strID;
	}

/**
 * 取得上層序號陣列
 * @param	intUserID 使用者序號
 * @param	intGroup 使用者群組序號
 * @return	回傳 false -> 失敗，Array[x] = y -> 成功，x: SubID => 代理商序號，MainID => 總代理序號，StockID => 股東序號
 */
	function GetArrayParentID($intUserID, $intGroup, $arrID){
		global $_Conn, $$_Conn;
		switch($intGroup){
			case 2:
				$arrID["SubID"] = $intUserID;
				break;
			case 3:
				$arrID["MainID"] = $intUserID;
				break;
			case 4:
				$arrID["StockID"] = $intUserID;
				break;
		}
		if($intUserID == 0)return $arrID;
		$strSQL = "select ParentID, MemberGroup from `bet_Member` where ID = ".$intUserID;
		if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
			$GLOBALS["errormessage"] = "Find Member Parent Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		if(PMA_mysql_num_rows($RS) > 0){
			$Rows = PMA_mysql_fetch_object($RS);
			$arrID = GetArrayParentID($Rows -> ParentID, $Rows -> MemberGroup, $arrID);
			if($arrID === false)return false;
		}
		return $arrID;
	}

//-------------------------------------------------------//
//Login_lib End
}
?>